﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Drawing;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Data;
using System.Windows.Interop;
using System.Windows;
using System.Runtime.InteropServices;
//using vbAccelerator.Components.ImageList;
using System.Diagnostics;
using System.Threading;
using System.Windows.Threading;

namespace AssignmentsManage.Tools
{
    //#region FileToImageIconConverter
    //public class FileToImageIconConverter
    //{
    //    private string _filePath;
    //    private System.Windows.Media.ImageSource _icon;

    //    public string FilePath { get { return _filePath; } } 

    //    public System.Windows.Media.ImageSource Icon
    //    {
    //        get
    //        {
    //            if (icon == null && System.IO.File.Exists(FilePath))
    //            {
    //                using (System.Drawing.Icon sysicon = System.Drawing.Icon.ExtractAssociatedIcon(FilePath))
    //                {
    //                    icon = System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon(
    //                              sysicon.Handle,
    //                              System.Windows.Int32Rect.Empty,
    //                              System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
    //                }
    //            }
 
    //            return icon;
    //        }
    //    }

    //    public FileToImageIconConverter(string filePath)
    //    {
    //        this.FilePath = filePath;
    //    }
    //} 
    //#endregion

    #region FileToImageIconConverter
    public class FileToImageIconConverter
    {
        private string filePath;
        private System.Windows.Media.ImageSource icon;
 
        public string FilePath { get { return filePath; } } 

        public System.Windows.Media.ImageSource Icon
        {
            get
            {
                if (icon == null && System.IO.File.Exists(FilePath))
                {
                    using (System.Drawing.Icon sysicon = System.Drawing.Icon.ExtractAssociatedIcon(FilePath))
                    {
                        icon = System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon(
                                  sysicon.Handle,
                                  System.Windows.Int32Rect.Empty,
                                  System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
                    }
                }
 
                return icon;
            }
        } 

        public FileToImageIconConverter(string filePath)
        {
            this.filePath = filePath;
        }
    } 

    #endregion 


}
